package org.websocket;

import org.springframework.lang.NonNull;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Description:
 * @Author: wxl
 * @CreateTime: 2023/2/15 13:43
 */
public class EasyWebSocketConfiguration implements WebSocketConfigurer {

    private String endPoint;

    private final EasyWebSshWebSocketHandler webSocketHandler;

    public EasyWebSocketConfiguration () {
        this.webSocketHandler = new EasyWebSshWebSocketHandler();
    }

    @Override
    public void registerWebSocketHandlers(@NonNull WebSocketHandlerRegistry registry) {
        registry.addHandler(this.webSocketHandler,getEndPoint())
                .addInterceptors(new EasyWebSocketInterceptor())
                .setAllowedOriginPatterns("*");
    }

    public String getEndPoint() {
        return endPoint;
    }

    public void setEndPoint(String endPoint) {
        this.endPoint = endPoint;
    }
}
